<template>
    <!-- 弹窗组件 -->
    <div class="dialog-box">
        <el-dialog v-model="dialogVisible" :title="dialogTitle" width="1000" class="review-dialog"
            :close-on-click-modal="false">
            <!-- 信息区 -->
            <div class="review-info">
                <div class="info-row flex_start_center">
                    <div class="info-item">
                        <div class="label">调拨单号</div> {{ dialogRow.transfer_no }}
                    </div>
                    <div class="info-item">
                        <div class="label">调拨日期</div> {{ dialogRow.transfer_date }}
                    </div>
                    <div class="info-item">
                        <div class="label">调拨仓库</div> {{ dialogRow.to_warehouse_name }}
                    </div>
                    <div class="info-item">
                        <div class="label">提交人</div> {{ dialogRow.submit_name }}
                    </div>
                    <div class="info-item">
                        <div class="label">提交时间</div> {{ dialogRow.submit_time }}
                    </div>
                </div>
            </div>
            <!-- 盘点产品 -->
            <div class="section-title">盘点产品</div>
            <el-table :data="productList" border style="width: 96%;" class="review-table">
                <el-table-column prop="product_name" label="产品名称" align="center" />
                <el-table-column prop="specification" label="规格型号" align="center" />
                <el-table-column prop="unit" label="单位" align="center" />
                <el-table-column prop="from_warehouse_name" label="调出仓库" align="center" />
                <el-table-column prop="stock_num" label="调拨数量" align="center" />
               
            </el-table>
            <!-- 审核意见 -->
            <div class="section-title" style="margin-top: 24px;">审核意见</div>
            <el-input v-model="reviewRemark" type="textarea" :rows="3" placeholder="" class="review-remark"
                maxlength="200" show-word-limit style="width: 96%;" />
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="dialogVisible = false">取消</el-button>
                    <el-button @click="handleApprove(3)" plain>审核拒绝</el-button>
                    <el-button type="primary" color="#626aef" @click="handleApprove(2)">审核通过</el-button>
                </div>
            </template>
        </el-dialog>


    </div>
</template>

<script setup lang="ts">
import { ref, watch, computed, reactive, onMounted } from "vue";
import type { FormInstance, FormRules } from 'element-plus';
import { ElMessage } from 'element-plus';
import api from "@/api";

// import SelectManagerDialog from '../';
// 接收父组件传入的值
const props = defineProps({
    dialogVisible: {
        type: Boolean,
        default: false
    },
    dialogType: {
        type: String,
        default: 'add'
    },
    dialogRow: {
        type: Object,
        default: () => ({})
    },
    productList: {
        type: Array,
        default: () => []
    }
});

const emit = defineEmits(['update:dialogVisible', 'submit', 'approve', 'reject']);

// 表单ref


const dialogTitle = computed(() => props.dialogType === 'add' ? '库存盘点审核' : '库存盘点审核');

// 监听对话框显示状态
const dialogVisible = computed({
    get: () => props.dialogVisible,
    set: (val) => {
        emit('update:dialogVisible', val);
    }
});
watch(() => dialogVisible.value, (val) => {
    if(val) {
    //   productList.value = props.dialogRow.stock_transfer_items;
    }
}, { deep: true });


const productList = computed(() => props.dialogRow.stock_transfer_items|| []);
const reviewRemark = ref("");

async function handleApprove(status: number) {

    //如果拒绝 意见不能为空
    if(status == 3) {
        if(!reviewRemark.value) {
            ElMessage.error('审核意见不能为空');
            return;
        }
    }

    const res = await api.product.stock_transfer_change_status({ ids: JSON.stringify([props.dialogRow.id]), status: status, audit_opinion: reviewRemark.value });
    if(res.code === 200) {
        ElMessage.success('提交成功');
        emit('update:dialogVisible', false);
    } else {
        ElMessage.error(res.message || '提交失败');
    }
}


</script>

<style lang="scss" scoped>
::v-deep .form-section {
    padding-top: 0px !important;
}

::v-deep .el-form-item__label {
    margin-left: 2px !important;
}

::v-deep .el-form-item__label-wrap {
    margin-left: 0px !important;
}

::v-deep .el-form-item {
    display: block;
}


:deep(.el-dialog) {
    --el-dialog-padding-primary: 0px;
}

:deep(.el-dialog__header) {
    padding: 10px 16px;
    border-bottom: 1px solid #f0f0f0;
    font-weight: bold;
}

:deep(.dialog-footer) {
    padding: 10px 16px;
    border-top: 1px solid #f0f0f0;
}

:deep(.el-dialog__headerbtn .el-dialog__close) {
    color: #000;
}

:deep(.el-dialog__body) {
    padding: 20px 10px;
    padding-right: 30px;
}

.review-dialog {
    ::v-deep .el-dialog__header {
        display: none;
    }

    ::v-deep .el-dialog__body {
        padding: 0 0 24px 0;
    }
}

.review-title {
    font-size: 22px;
    font-weight: bold;
    color: #222;
    padding: 24px 32px 0 32px;
    line-height: 1.2;
}

.review-info {
    background: #f5f7fa;
    padding: 18px 32px 8px 32px;
    margin: 18px 0 0 0;
    border-radius: 2px;

    .info-row {
        display: flex;
        flex-wrap: wrap;
        gap: 0 32px;
        .info-item {
            min-width: 96px;
            font-size: 14px;
            color: #333;
            margin-bottom: 10px;
            .label {
                color: #888;
                margin-right: 6px;
                margin-bottom: 6px;
            }
        }
    }
}

.section-title {
    font-weight: bold;
    font-size: 16px;
    color: #222;
    margin: 24px 0 12px 0;
    padding-left: 32px;

    // 添加左边元素  
    &::before {
        content: '';
        display: inline-block;
        width: 4px;
        height: 16px;
        background: #626aef;
        margin-right: 8px;
    }

}

.review-table {
    margin: 0 32px;

    ::v-deep th {
        background: #f5f7fa;
        color: #222;
        font-weight: bold;
        font-size: 15px;
    }

    ::v-deep td {
        color: #333;
        font-size: 15px;
        background: #fff;
        word-break: break-all;
        white-space: pre-line;
    }
}

.review-remark {
    margin: 0 32px;
    margin-top: 8px;

    ::v-deep textarea {
        background: #fafbfc;
        color: #333;
        font-size: 15px;
        border-radius: 2px;
        min-height: 60px;
        resize: none;
    }
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 0 32px 24px 32px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    padding-top: 20px;
}
</style>
